/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package clientprogram;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 *
 * @author ASUS
 */
public class LockScreen extends Thread{
    public static boolean working = true;
    JFrame frame;
    InputManager inputManager;
    LoginForm dialog;
    public LockScreen() throws IOException
    {
        frame = new JFrame("Login");
        frame.setLocationRelativeTo(null);
        frame.setLayout(new BorderLayout());
        frame.add(new Component() {
                BufferedImage img = ImageIO.read(new File("lockimage.jpg"));

                @Override
                public void paint(Graphics g) {
                    super.paint(g);
                    g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
                }
            });
        frame.setAlwaysOnTop(true);
        //e.printStackTrace();
        //}
        frame.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {

                        dialog.setVisible(true);
                        //dialog.toFront();
                    }
                });
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mousePressed(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void mouseExited(MouseEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setUndecorated(true);
        
        dialog = new LoginForm(frame, true);
        dialog.setLocationRelativeTo(frame);
        dialog.setAlwaysOnTop(true);
        start();
    }
    
    public void SetFullScreen()
    {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gs = ge.getDefaultScreenDevice();
        gs.setFullScreenWindow(frame);
    }
    
    public void run()
    {
        //SetFullScreen();
        frame.setVisible(true);
        try
        {
            Robot robot = new Robot();
            while(working)
            {
                robot.keyRelease(KeyEvent.VK_ALT);
                robot.keyRelease(KeyEvent.VK_TAB);
                frame.requestFocus();
                Thread.sleep(10);
            }
            new ClientMain();
            frame.setVisible(false);
            frame.dispose();
        }
        catch(Exception e)
        {

        }
    }
}
